console.log('published')
var supplierId = window.localStorage.getItem('userId')
$.ajax({
    url:webUrl + '/goods/findBySupplierId',
    data:{
        supplierId:supplierId
    },
    success(data){
        console.log(data)
        for (let k in data.content){
            if(data.content[k].goodsSatus == '1'){
                let goodsInfo = `<tr style="border-bottom:1px solid #e3e3e3">
                                <td>
                                    <div class="img-product">
                                        <img src="`+data.content[k].productPicture+`" alt="">
                                    </div>
                                    <div class="name-product">
                                        `+data.content[k].brandName+` <br />`+data.content[k].specificationModel+`
                                    </div>
                                </td>
                                <td>
                                    <div class="total">
                                        $`+data.content[k].price+`
                                    </div>
                                </td>
                                <td>
                                    <div class="quanlity">
                                        <span>`+data.content[k].inventorySituation+`</span>
                                    </div>
                                </td>
                                <td>
                                    <div class="total">
                                        $`+data.content[k].concessionalRate+`
                                    </div>
                                </td>
                                <td>
                                    <a href="#" title="">
                                        123456789
                                    </a>
                                </td>
                                <td>
                                    <button class="btn btn-secondary btn-success up" data-id="`+data.content[k].goodsId+`">上架</button>
                                    <button class="btn btn-secondary down" data-id="`+data.content[k].goodsId+`">下架</button>
                                </td>
                            </tr>`;
                $('.buyGoodsList').append(goodsInfo)
            }else{
                let goodsInfo = `<tr style="border-bottom:1px solid #e3e3e3">
                                <td>
                                    <div class="img-product">
                                        <img src="`+data.content[k].productPicture+`" alt="">
                                    </div>
                                    <div class="name-product">
                                        `+data.content[k].brandName+` <br />`+data.content[k].specificationModel+`
                                    </div>
                                </td>
                                <td>
                                    <div class="total">
                                        $`+data.content[k].price+`
                                    </div>
                                </td>
                                <td>
                                    <div class="quanlity">
                                        <span>`+data.content[k].inventorySituation+`</span>
                                    </div>
                                </td>
                                <td>
                                    <div class="total">
                                        $`+data.content[k].concessionalRate+`
                                    </div>
                                </td>
                                <td>
                                    <a href="#" title="">
                                        123456789
                                    </a>
                                </td>
                                <td>
                                    <button class="btn btn-secondary up" data-id="`+data.content[k].goodsId+`">上架</button>
                                    <button class="btn btn-secondary btn-success down" data-id="`+data.content[k].goodsId+`">下架</button>
                                </td>
                            </tr>`;
                $('.buyGoodsList').append(goodsInfo)
            }

        }
    }
})
function chstatConfirm(flag, params) {
    if ($(".alert").length > 0) {
        $(".alert").remove();
    }
    var html = `<div class="alert" style="position: fixed;border:1px solid #e3e3e3;background:#fff;top: 30%;left:50%;width: 10%;margin-left:-5%;text-align: center;z-index: 99999" role="alert">
                    `+flag+`
                </div>`;
    $("body").append(html);
    $('.alert').alert()
    setTimeout(function () {
        $(".alert").remove();
    },1500)

}

$(document).on('click','.up',function(){
    let goodsId = $(this).attr('data-id')
    if($(this).hasClass('btn-success')){
        return
    }

    $(this).addClass('btn-success').siblings('.down').removeClass('btn-success')
    changeType(goodsId)
    chstatConfirm('上架成功!',1)
})
$(document).on('click','.down',function(){
    let goodsId = $(this).attr('data-id')
    if($(this).hasClass('btn-success')){
        return
    }
    $(this).addClass('btn-success').siblings('.up').removeClass('btn-success')
    changeType(goodsId)
    chstatConfirm('下架成功!',1)
})
function changeType(goodsId){
    $.ajax({
        url:webUrl + '/goods/updataGoodsStatusDw',
        method:'POST',
        data:{
            goodsId:goodsId
        },
        success(data){
            console.log(data)
        }
    })
}
